#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @who:     spacelacc
# @when:    2025/04/26
# @what:    Start running program 'makeprobepairer'
# @vers:    V1


import os
import configparser
from PySide6.QtGui     import QScreen
from PySide6.QtWidgets import QApplication, QWidget
from wtprobepairer     import ProbePairerWidget


approot = os.path.dirname(os.path.abspath(__file__))
config = os.path.join(approot, 'config.cfg')
styles = os.path.join(approot, 'styles.qss')
filebase = os.path.join(approot, 'ultrasonic_probe')
basebase = os.path.join(approot, 'sqlite3_database')

arch = {}
arch['approot'] = approot
arch['config'] = config
arch['styles'] = styles
arch['filebase'] = filebase
arch['basebase'] = basebase

# Checking for configuration, if not exist, then create
if not os.path.exists(filebase):
    os.mkdir(filebase)
if not os.path.exists(basebase):
    os.mkdir(basebase)
if not os.path.exists(config):
    with open(config, 'w') as writer:
        writer.write('')
if not os.path.exists(styles):
    with open(styles, 'w') as writer:
        writer.write('')

# Setup configurations here
adapter = configparser.ConfigParser(allow_no_value=True)
adapter.read(config)

# Setup stylesheet here
application = QApplication()
with open(styles, 'r', encoding='utf-8') as reader:
    application.setStyleSheet(reader.read())

# Setup screen size here
screen = application.primaryScreen()
width  = screen.size().width()
height = screen.size().height()

# Setup application GUI here
probepairer = ProbePairerWidget(0.8*width, 0.7*height, adapter, arch)
probepairer.show()

# Now, start infinite event loop here
application.exec()
